package com.xfly.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.bean.AddressBean;
import com.ptmall.app.utils.TimeUtil;
import com.ptmall.app.utils.Utils;
import com.xfly.app.bean.QbBean;

import java.util.List;


/**
 * Created by Administrator on 2018/1/12.
 */

public class QbAdapter extends BaseAdapter {

    private Context mContext;
    private List<QbBean> mDataList;
    private LayoutInflater mLayoutInflater;

    public QbAdapter(Context context, List<QbBean> list) {
        this.mContext = context;
        this.mDataList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void pushData(List<QbBean> list){
        this.mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(mDataList == null){
            return 0;
        }
        return mDataList.size();
    }

    Click click;

    public void setClick(Click click){
        this.click = click;
    }


    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.item_qb, parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        QbBean bean = mDataList.get(position);

        switch (bean.mold){
            case "in":

                viewHolder.type.setText("收入");
                break;
            case "out":
                viewHolder.type.setText("支出");
                break;
        }

        viewHolder.num.setText(bean.money);
        viewHolder.time.setText(TimeUtil.getStrTime(bean.create_time+""));


        return convertView;
    }

    class ViewHolder {

        TextView type,time,num;

        ViewHolder(View view) {
            type = (TextView) view.findViewById(R.id.type);
            time = (TextView) view.findViewById(R.id.time);
            num = (TextView) view.findViewById(R.id.num);
        }
    }

    public  interface Click{
        void Click(int position);
        void Click2(int position);
    }

}
